<%@ page pageEncoding="utf-8"%>
<%request.setCharacterEncoding("utf-8");%>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@include file="/include/pageexpires.jsp"%>
<%@include file="/include/filepath.jsp"%>
<%@include file="/include/currentuserinfo.jsp"%>
<html>
  <head>
    <title>信息列表</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <link type="text/css" rel="stylesheet" href="<%=ctxpath%>/themes/newstyle/styles/mac/macmenu.css" id="menuStyleSheet">
  </head>
  <%
  String flag = (String)request.getAttribute("flag");
  String sort_field="c.sendtime";//默认值:以用户ID排序
  String sort_type="desc";
  if(request.getAttribute("chatMessage") != null){
    request.setAttribute("chatMessage",(com.ecomm.chat.pojo.ChatMessage)request.getAttribute("chatMessage"));
  }
  
  if(request.getAttribute("sort_field")!=null){
    sort_field = (String)request.getAttribute("sort_field");  //得到传来的参数
  }
  if(request.getAttribute("sort_type")!=null){
    sort_type =(String)request.getAttribute("sort_type");
  }
  
  %>
  <script language="javascript">
    //分页必须包含的JS
    function checkForm(operType){
    if(operType=='turnPage'){
       chatRemindForm.action="<%=ctxpath%>/chat/message.do?method=search&flag=<%=flag%>";
        chatRemindForm.submit();
        return true;
    }
}
       function opendchat(senduserid,parentid,type,bigtype){
        //alert(senduserid);
        <%
        if(flag != null && flag.equals("1")){
      %>
      //window.document.location.reload();
      window.close();
      <%}%>
        window.open("<%=ctxpath%>/chat/frameset_history.jsp?nick=<%=userid%>&id="+senduserid+"&parentid="+parentid+"&type="+type+"&bigtype="+bigtype,senduserid, "status=no,resizable=yes,scrollbars=no,toolbar=no,WIDTH=500,HEIGHT=450")
      }
 function deletechatall(){
    var num = 0;
    var isSub = false;
    for (var i=0;i<chatRemindForm.elements.length;i++){
        if(chatRemindForm.elements[i].type == 'checkbox'){
        if (chatRemindForm.elements[i].checked && chatRemindForm.elements[i].name != 'chkall'){
            num  = num + 1;
        }
        }
    }
        if(num > 0){
        if(confirm('确认删除消息吗？')){
            isSub = true;
        }
    }else alert('请选择删除的消息');
    if(isSub){
       chatRemindForm.action="<%=ctxpath%>/chat/message.do?method=search&deleteflag=1&flag=<%=flag%>";
      chatRemindForm.submit();
      return true;
      }
   }      
     
function CheckAll(form)  {
  for (var i=0;i<form.elements.length;i++)    {
    var e = form.elements[i];
    if (e.name != 'chkall')       e.checked = form.chkall.checked;
   }
  }
                                     </script>
  <body scroll="no" id="body">
    <table id="display" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
      <tr>
        <td valign="top">
          <div id="layer1" style="width:100%; height:100%; z-index:50; overflow: auto;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
              <tr>
                <td valign="top" align="center">
                  <table cellspacing="0" cellpadding="0" class="labeltable_middle">
                    <tr>
                      <td class="labeltd_middle">
                        <%
                        java.util.ArrayList al = (java.util.ArrayList)request.getAttribute("getMessage");
                        //System.out.println("111"+al.size());
                        if(al != null && al.size() >0){
                        %>
                        <form  name="chatRemindForm" action="/chat/remind" method="post">
                          <input name="sort_field" type="hidden" value="<%=sort_field%>">
                          <input name="sort_type" type="hidden" value="<%=sort_type%>">
                          <table  class="labeltable_middle_table" width="100%" height="100%" cellpadding="0" cellspacing="0" border="0">
                            <tr>
                              <td class="labeltable_middle_td" align="center" colspan="15">
                                
                                <%
                                if(flag != null && flag.equals("1")){
                                  out.print("未查收消息列表");
                                }else{
                                  out.print("历史消息列表");
                                }
                                %>
                              </td>
                            </tr>
                            <tr>
                              <td  class="labeltable_middle_td" ><input type="checkbox" name="chkall" onClick="CheckAll(chatRemindForm)"></td>
                              <td class="labeltable_middle_td" align="center">消息内容</td>
                              <td class="labeltable_middle_td" align="center">
                                <%=com.ecomm.util.StringUtils.getTableTitleHtml(sort_field,sort_type,"发送时间","c.sendtime","chatRemindForm","turnPage",ctxpath+"/images/asc.gif",ctxpath+"/images/desc.gif")%>
                              </td>
                              <td class="labeltable_middle_td" align="center">
                                <%=com.ecomm.util.StringUtils.getTableTitleHtml(sort_field,sort_type,"发送人","c.senduserid","chatRemindForm","turnPage",ctxpath+"/images/asc.gif",ctxpath+"/images/desc.gif")%>
                              </td>
                              <td class="labeltable_middle_td" align="center">
                                <%=com.ecomm.util.StringUtils.getTableTitleHtml(sort_field,sort_type,"接收人","r.acceptuserid","chatRemindForm","turnPage",ctxpath+"/images/asc.gif",ctxpath+"/images/desc.gif")%>
                              </td>
                              <td class="labeltable_middle_td" align="center">
                                <%=com.ecomm.util.StringUtils.getTableTitleHtml(sort_field,sort_type,"消息类型","c.bigtype","chatRemindForm","turnPage",ctxpath+"/images/asc.gif",ctxpath+"/images/desc.gif")%>
                              </td>
                            </tr>
                            <%
                            for(int i = 0;i< al.size();i++){
                                  Object[] object = (Object[])al.get(i);
                                  // c.id,c.message , c.url ,c.senduserid,c.sendtime,c.type,r.acceptuserid,c.bigtype,c.parentid
                                  //select cid,c.senduserid ,c.parentid,c.type,c.message,c.sendtime
                                  if(object != null){
                            %>
                            <tr>
                              <td><input type='checkbox' name='ids' value='<%=(String)object[0]%>,<%=(String)object[3]%>,<%=(String)object[6]%>'></td>
                              <td align="center">
                                <%
                                if((String)object[2] != null && !((String)object[2]).equals("")){
                                %>
                                <a href="<%=(String)object[2]%>"><%=(String)object[1]%></a>
                                <%
                                }else{
                                %>
                                <%=(String)object[1]%>
                                <%}%>&nbsp;
                              </td>
                              <td align="center"><%=(String)object[4]%>&nbsp;</td>
                              <td align="center">
                                <%
                                com.ecomm.chat.pojo.ChatUserInfo cui = (com.ecomm.chat.pojo.ChatUserInfo)com.ecomm.chat.manager.ChatUserInfoManager.getInstance().getChatUserInfoByUserid((String)object[3]);
                                if(cui != null){
                                  if(!((String)object[3]).equals(userid)){
                                
                                %>
                              <img src="<%=ctxpath%>/chat/img/online/<%=cui.getImgPath()%>_<%=cui.getOnlinestate()%>.gif" >  <a href="#"  onclick="opendchat('<%=(String)object[3]%>','<%=(String)object[8]%>','<%=(String)object[5]%>','<%=(String)object[7]%>')" > <%=com.ecomm.util.CommonMethod.getUserNameByUserID((String)object[3])%></a>
                                <%
                                
                                  }else{
                                %>
                                <img src="<%=ctxpath%>/chat/img/online/<%=cui.getImgPath()%>_<%=cui.getOnlinestate()%>.gif" ><%=com.ecomm.util.CommonMethod.getUserNameByUserID((String)object[3])%>
                                <%
                                  }
                                }
                                %>&nbsp;
                              </td>
                              <td align="center">
                                <%
                                com.ecomm.chat.pojo.ChatUserInfo cuiaccept = (com.ecomm.chat.pojo.ChatUserInfo)com.ecomm.chat.manager.ChatUserInfoManager.getInstance().getChatUserInfoByUserid((String)object[6]);
                                if(cuiaccept != null){
                                  if(!((String)object[6]).equals(userid)){
                                %>
                                   <img src="<%=ctxpath%>/chat/img/online/<%=cuiaccept.getImgPath()%>_<%=cuiaccept.getOnlinestate()%>.gif" > <a href="#"  onclick="opendchat('<%=(String)object[6]%>','<%=(String)object[8]%>','<%=(String)object[5]%>','<%=(String)object[7]%>')" >     <%=com.ecomm.util.CommonMethod.getUserNameByUserID((String)object[6])%></a>
                                <%
                                  }else{
                                %>
                                <img src="<%=ctxpath%>/chat/img/online/<%=cuiaccept.getImgPath()%>_<%=cuiaccept.getOnlinestate()%>.gif" ><%=com.ecomm.util.CommonMethod.getUserNameByUserID((String)object[6])%>
                                <%
                                  }
                                }
                                %>&nbsp;
                              </td>
                              <td align="center"><%=com.ecomm.util.CommonMethod.bigtype.get((String)object[7])%>
                                <% if((String)object[7] != null && ((String)object[7]).equals("2")) out.println("("+com.ecomm.util.CommonMethod.getType((String)object[7],(String)object[5])+")");%>&nbsp;
                              </td>
                            </tr>
                            <%
                                  }
                            }
                            %>
                            <tr>
                              <td colspan="15" align="center">
                                <input type="button" value=" 删  除" name="deleteall" onclick="deletechatall()">
                                <%=(String)request.getAttribute("pageview")%>
                              </td>
                            </tr>
                          </table>
                        </form>
                        <%
                        }else{
                          out.print("没有消息");
                        }
                        %>
                      </td>
                    </tr>
                  </table>   
                  <table border="0" cellpadding="0" cellspacing="0" class="labeltable_bottom">
                    <tr>
                      <td class="left">&nbsp;</td>
                      <td class="center">&nbsp;</td>
                      <td class="right">&nbsp;</td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </div>
        </td>
      </tr>
    </table>
  </body>
</html>





